package com.dfrz.service.impl;

import com.dfrz.entity.MyCollection;
import com.dfrz.mapper.MyCollectionMapper;
import com.dfrz.service.MyCollectionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 29877
 */
@Service
public class MyCollectionServiceImpl implements MyCollectionService{
    @Resource
    private MyCollectionMapper myCollectionMapper;


    @Override
    public List<MyCollection> selectcollections(Integer uid, Integer page) {
        int pageSize=7;
        int index=(page-1)*pageSize;
        List<MyCollection> collections1=myCollectionMapper.selectCollection(uid,index);
        List<MyCollection> collections2=new ArrayList<>();
        Iterator<MyCollection> iterator=collections1.iterator();
        while (iterator.hasNext()){
            MyCollection col=iterator.next();
            String imgUrl=myCollectionMapper.selectcollectimg(col.getVideoId());
            col.setVideoImg(imgUrl);
            collections2.add(col);
        }
        return collections2;
    }

    @Override
    public List<MyCollection> selectcollections2(Integer uid, Integer page) {
        int pageSize=15;
        int index=(page-1)*pageSize;
        return myCollectionMapper.selectCollection2(uid,index);
    }
    @Override
    public boolean collectionstatus(Integer uid, Integer vid) {
     List<MyCollection> list=myCollectionMapper.collectionstatus(uid, vid);
     if (list.isEmpty()){
         return false;
     }
     return true;
    }
    @Override
    public void addcollection(Integer uid, Integer vid) {
        String time= LocalDateTime.now().toString();
        myCollectionMapper.addcollection(uid,vid,time);
    }
    @Override
    public void delectcollection(Integer uid, Integer vid) {
        myCollectionMapper.deletecollection(uid,vid);
    }

}
